<?php
include 'laczenie_baza.php';
$pacjent =checkData($_SESSION['zalogowany']);



/* zapytanie do konkretnej tabeli */
$wynik = mysql_query("SELECT * FROM kalendarz_terminy WHERE pacjent = '".$pacjent."' ");
if(!$wynik){
		$GLOBALS['komunikat'] = "Problem z bazą danych. Odrzucone zapytanie.";
		mysql_close($link);
		return false;
	}

	$date = getdate();
	if($date['mon'] <10)
		$date['mon'] = "0".$date['mon'];
	if($date['mday'] < 10)
		$date['mday'] = "0".$date['mday'];
	
	$curDate = $date['year']."-".$date['mon']."-".$date['mday'];
	
	$localtime = localtime(time(), true);
	if($localtime['tm_hour'] < 10)
		$localtime['tm_hour'] = "0".$localtime['tm_hour'];
	if($localtime['tm_min'] < 10)
		$localtime['tm_min'] = "0".$localtime['tm_min'];
	if($localtime['tm_sec'] < 10)
		$localtime['tm_sec'] = "0".$localtime['tm_sec'];
	$curTime = $localtime['tm_hour'].":".$localtime['tm_min'].":".$localtime['tm_sec'];
	$curTime = "12:46:00";
	

if(mysql_num_rows($wynik) > 0) {
	echo '<center><h3><table><tr><th>Data Wizyty </th><th> Godzina </th><th> Lekarz </th></tr>';
	echo "<table cellpadding=\"2\" border=1>";
	while($r = mysql_fetch_object($wynik)) {
		if($r->data_terminu > $curDate || ($r->data_terminu == $curDate && $r->godzina > $curTime))
		{
			$i = 0;
		echo "<tr>";
		echo "<td>".$r->data_terminu."</td>";
		echo "<td>".$r->godzina."</td>";
		echo "<td>".$r->lekarz."</td>";
		
		echo "</tr>";
		}
		else if(isset($i)){
			$query = "DELETE FROM kalendarz_terminy WHERE data_terminu='$r->data_terminu' AND godzina='$r->godzina'";
			$wykre[$i++] = "<h3><td>$r->data_terminu</td><td>$r->godzina</td><td>wykreślono - termin upłynął</td></h3>";
			mysql_query($query);
			
		}
	}
	echo "</table></h3></center>";
	if(isSet($wykre)) {
	foreach ($wykre as $r)
	{
	echo "<tr>$r</tr>";
	}
	}
	}
else { 
	$GLOBALS['komunikat'] = "Problem z bazą danych. Odrzucone zapytanie.";
	mysql_close($link);
	return false;
}


	?>